package com.me.screen;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.me.constant.Constant;
import com.me.enums.ScreenEnum;
import com.me.memorytest.MainMemoryTest;

public class EndGame extends BaseScreen {

	Image imgBackGround;
	TextButton btn_mainMenu;
	TextButton btn_ShareScore;
	TextButton btn_shareGame;
	Label lb_yourClicks;
	private Image img_bgTop;
	
	@Override
	public void show() {
		super.show();
		
		imgBackGround = new Image(Constant.atlas.findRegion("datagame/backGround"));
		
		btn_mainMenu = new TextButton("Main menu", Constant.skin, "textButton_49_bold_EndGame");
		btn_mainMenu.setX(440);
		btn_mainMenu.setY(450);
		btn_mainMenu.setWidth(450);
		btn_mainMenu.setHeight(100);
		btn_mainMenu.addListener(new ClickListener(){
			@Override
			public void clicked(InputEvent event, float x, float y) {
				super.clicked(event, x, y);
				MainMemoryTest.getScreenManager().createScreen(ScreenEnum.MENU_SCREEN);
				MainMemoryTest.getScreenManager().getScreen().show();
			}
		});
		
		img_bgTop = new Image(Constant.atlas.findRegion("datagame/menu-bottom-thanh-ngang"));
		img_bgTop.setBounds(0, 0, Constant.STAGE_WIDTH, 90);
		
		btn_ShareScore = new TextButton("Share score", Constant.skin, "textButton_49_bold_EndGame");
		btn_ShareScore.setX(440);
		btn_ShareScore.setY(320);
		btn_ShareScore.setWidth(450);
		btn_ShareScore.setHeight(100);
		btn_ShareScore.addListener(new ClickListener(){
			@Override
			public void clicked(InputEvent event, float x, float y) {
				super.clicked(event, x, y);
				MainMemoryTest.getScreenManager().createScreen(ScreenEnum.HIGH_SCORE_SCREEN);
				MainMemoryTest.getScreenManager().getScreen().show();
			}
		});
		
		btn_shareGame = new TextButton("Share game", Constant.skin, "textButton_49_bold_EndGame");
		btn_shareGame.setX(440);
		btn_shareGame.setY(200);
		btn_shareGame.setWidth(450);
		btn_shareGame.setHeight(100);
		btn_shareGame.addListener(new ClickListener(){
			@Override
			public void clicked(InputEvent event, float x, float y) {
				super.clicked(event, x, y);
				String str = "https://play.google.com/store/apps/developer?id=gameStudio";
				MainMemoryTest.getApi().shareTextUrl(str);
			}
		});
		
		lb_yourClicks = new Label("Your clicks: "+Constant.iCountClicked, Constant.skin, "labelMenu");
		lb_yourClicks.setX(10);
		lb_yourClicks.setY(10);
		
		stage.addActor(imgBackGround);
		stage.addActor(img_bgTop);
		stage.addActor(btn_mainMenu);
		stage.addActor(btn_ShareScore);
		stage.addActor(btn_shareGame);
		stage.addActor(lb_yourClicks);
	}

	@Override
	public void render(float arg0) {
		Gdx.gl.glClearColor(0, 0, 0.2f, 1);
		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

		// tell the camera to update its matrices.
		camera.update();

		// tell the SpriteBatch to render in the coordinate system specified by the camera.
		sb.setProjectionMatrix(camera.combined);

		// begin a new batch and draw the bucket and all drops
		sb.begin();
		sb.end();

		stage.setViewport(Constant.STAGE_WIDTH, Constant.STAGE_HEIGHT, false);
	}

}
